﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;

namespace PleaseORM.Drivers
{
	public abstract class AbstractReflectionDriver : AbstractDriver
	{
		private readonly Type _connectionType;
		private readonly Type _commandType;

		protected AbstractReflectionDriver(string assemblyFile, string connectionTypeName, string commandTypeName)
		{
			var assembly = Assembly.LoadFrom(assemblyFile);
			_connectionType = assembly.GetType(connectionTypeName);
			_commandType = assembly.GetType(commandTypeName);
		}

		public override IDbCommand CreateCommand()
		{
			return Activator.CreateInstance(_commandType) as IDbCommand;
		}

		public override IDbConnection CreateConnection()
		{
			return Activator.CreateInstance(_connectionType) as IDbConnection;
		}
	}
}
